from PyQt5.QtWidgets import QFrame, QStackedWidget, QHBoxLayout, QLabel, QTableWidgetItem, QGridLayout
from qfluentwidgets import SearchLineEdit, TableWidget, PrimaryPushButton, FluentIcon


class BatchDownloadFrame(QFrame):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.layout = QGridLayout(self)
        self.layout.setContentsMargins(10, 70, 10, 10)

        self.lineEdit = SearchLineEdit(self)
        self.lineEdit.setFixedSize(800, 35)
        self.lineEdit.setClearButtonEnabled(True)
        self.lineEdit.setPlaceholderText("请输入作者主页链接，如：https://v.douyin.com/iYbUtePo/")
        self.layout.addWidget(self.lineEdit, 0, 0)

        self.button = PrimaryPushButton(FluentIcon.DOWNLOAD, 'Download', self)
        self.layout.addWidget(self.button, 0, 1)

        self.table = TableWidget(self)
        # enable border
        self.table.setBorderVisible(True)
        self.table.setBorderRadius(8)

        self.table.setWordWrap(False)
        headers = ['序号', '个人主页链接', '原视频链接', '视频大小', '下载进程', '下载时间']

        self.table.setRowCount(20)
        self.table.setColumnCount(len(headers))
        songInfos = [
            ['1', 'https://v.douyin.com/iYbUtePo/', 'https://v.douyin.com/iYbyLLfq/', '19.1M', '已完成', '2024-04-16 15:32:33'],
        ]
        for i, songInfo in enumerate(songInfos):
            for j in range(len(headers)):
                self.table.setItem(i, j, QTableWidgetItem(songInfo[j]))

        self.table.verticalHeader().hide()
        self.table.setHorizontalHeaderLabels(headers)
        self.table.resizeColumnsToContents()
        self.layout.addWidget(self.table, 1, 0, 1, 2)


class BatchDownloadInterface(QFrame):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setObjectName('BatchDownload')
        self.stackWidget = QStackedWidget(self)
        self.layout = QHBoxLayout(self)
        self.batchDownloadLabel = QLabel(self.tr("批量视频下载"), self)
        self.__initWidget()

    def __initWidget(self):
        self.homeFrame = BatchDownloadFrame()
        self.stackWidget.addWidget(self.homeFrame)
        self.stackWidget.setCurrentIndex(0)
        self.__setQss()
        self.__initLayout()
        self.__connectSignalToSlot()

    def __initLayout(self):
        self.batchDownloadLabel.move(60, 63)
        self.layout.setContentsMargins(10, 70, 10, 10)
        self.layout.setSpacing(0)
        self.layout.addWidget(self.stackWidget)

    def __setQss(self):
        """ set style sheet """
        self.stackWidget.setObjectName('stackWidget')
        self.batchDownloadLabel.setObjectName('batchDownloadLabel')
        self.batchDownloadLabel.resize(200, 63)
        self.setStyleSheet("QLabel#batchDownloadLabel {"
                           "font: 33px 'Microsoft YaHei Light';"
                           "background-color: transparent;"
                           "color: black;"
                           "}")

    def __connectSignalToSlot(self):
        pass
